package com.neutech.solar.util;

import com.neutech.solar.constant.Constant;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * 图片工具类
 * 使用I/O流加载图片
 * I：inputStream
 * O：OutputStream
 * @author：DELL
 * @version：1.0
 * @date：2021/1/25 11:08
 */
public class ImageUtil {

    public static Map<String,Image> maps = new HashMap<>();
    static {
        maps.put("bg",ImageUtil.getImage("bg.png"));
        maps.put("Sun",ImageUtil.getImage("Sun.png"));
        maps.put("Mercury",ImageUtil.getImage("Mercury.png"));
        maps.put("Venus",ImageUtil.getImage("Venus.png"));
        maps.put("Earth",ImageUtil.getImage("Earth.png"));
        maps.put("Mars",ImageUtil.getImage("Mars.png"));
        maps.put("Jupiter",ImageUtil.getImage("Jupiter.png"));
        maps.put("Saturn",ImageUtil.getImage("Saturn.png"));
        maps.put("Uranus",ImageUtil.getImage("Uranus.png"));
        maps.put("Neptune",ImageUtil.getImage("Neptune.png"));
        maps.put("Halley",ImageUtil.getImage("Halley.png"));


        maps.put("smallPlanet",ImageUtil.getImage("Planet.png"));
    }
    private ImageUtil(){}



    public static Image getImage(String imageName){
        URL u = ImageUtil.class.getClassLoader().getResource(Constant.IMAGE_PATH_PRE + imageName);
        // 提高文件读取效率
        BufferedImage img = null;
        try{
            img = ImageIO.read(u);
        }catch (Exception e){
            // 在控制台打印错误信息
            e.printStackTrace();
        }
        return img;
    }
}